package com.glorysoft.lipuxinpda.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.glorysoft.lipuxinpda.R;
import com.glorysoft.lipuxinpda.entity.MaterialInfoEntity;

import java.util.List;

public class MaterialAdapter extends RecyclerView.Adapter<MaterialAdapter.MaterialViewHolder>{
    private List<MaterialInfoEntity> mList;

    public void setmList(List<MaterialInfoEntity> mList) {
        this.mList = mList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public MaterialViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_materiel, parent, false);
        return new MaterialViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MaterialViewHolder holder, int position) {
        holder.tv_material_type.setText(mList.get(position).getMATERIAL_TYPE());
        holder.tv_material_model.setText(mList.get(position).getMATERIAL_MODEL());
    }

    @Override
    public int getItemCount() {
        return mList == null?0:mList.size();
    }

    class MaterialViewHolder extends RecyclerView.ViewHolder{

        private TextView tv_material_type;//物料类型
        private TextView tv_material_model;//物料模型

        public MaterialViewHolder(View itemView) {
            super(itemView);
            tv_material_type =  itemView.findViewById(R.id.tv_material_type);
            tv_material_model =  itemView.findViewById(R.id.tv_material_model);
        }
    }
}
